package com.coin.liu.Utils;


import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: bruceliu
 * @Date: 2019/12/10 14:33
 * @QQ:1241488705
 * @Description: 分页的工具类
 */
public class PageUtils<T> {

    private Long page;  //当前页码
    private Long limit;  //页面大小
    private long totalCount; //总条数
    private long pageCount;  //总页数???

    private List<T> records; //每页的数据集合

    private long numberStart; //开始的页码序号
    private long numberEnd;  //结束序号
    private List<Long> numbers=new ArrayList<Long>(); //所有需要存入

    public PageUtils() {
    }

    public PageUtils(Long page, Long limit, Long totalCount, List<T> records) {
        this.page = page;
        this.limit = limit;
        this.totalCount = totalCount;
        this.records = records;

        //计算一下总页数
        this.pageCount=(totalCount%limit==0)?(totalCount/limit):(totalCount/limit+1);

        //数学算法
        // -----------偷偷的给页码序号赋值------------------
        // 一共显示10个页面 动态伸缩
        if (this.pageCount <= 10) {
            this.numberStart = 1;
            this.numberEnd = pageCount;
        } else {
            this.numberStart = page - 4;
            this.numberEnd = page + 5;
            if (numberStart < 1) {
                this.numberStart = 1;
                this.numberEnd = 10;
            } else if (numberEnd > pageCount) {
                this.numberEnd = pageCount;
                this.numberStart = pageCount - 9;
            }
        }
        // -----------偷偷的给页码序号赋值------------------
        for(long i=numberStart;i<=numberEnd;i++){
            System.out.println(i);
            numbers.add(i);
        }
    }

    public List<Long> getNumbers() {
        return numbers;
    }

    public void setNumbers(List<Long> numbers) {
        this.numbers = numbers;
    }

    public long getPageIndex() {
        return page;
    }

    public void setPageIndex(long pageIndex) {
        this.page= pageIndex;
    }

    public long getPageSize() {
        return limit;
    }

    public void setPageSize(long pageSize) {
        this.limit = pageSize;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public long getPageCount() {
        return pageCount;
    }

    public void setPageCount(long pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public long getNumberStart() {
        return numberStart;
    }

    public void setNumberStart(long numberStart) {
        this.numberStart = numberStart;
    }

    public long getNumberEnd() {
        return numberEnd;
    }

    public void setNumberEnd(long numberEnd) {
        this.numberEnd = numberEnd;
    }
}
